import bytedance.context
import bytedlogger
import logid
import pytest

from apitest.engine.logging import logger


def pytest_runtest_teardown(item):
    log_id = logid.generate()
    bytedance.context.set("logid", log_id)
    bytedlogger.thread_storage[b'_logid'] = bytes(log_id, encoding='utf-8')


@pytest.fixture
def data(request):
    """用于数据驱动参数化
    """
    data: dict = request.param
    logger.info("用例入参：%s" % data)
    return data


@pytest.fixture
def title(request):
    """用于数据驱动参数化
    """
    title: str = request.param
    return title

# TODO 夹具方法需自行实现
# @pytest.fixture(scope="session")
# def ShCrmApiService():
#     """网电平台接口实例化
#     """
#     auth = get_token()
#     service = ShCrmApiService(auth=auth)
#     yield service
#     service.client.close()
